package com.fzhucc.modules.subject.rest;

import com.fzhucc.annotation.AnonymousAccess;
import com.fzhucc.annotation.Log;
import com.fzhucc.base.BaseEntity.Update;
import com.fzhucc.base.PageDTO;
import com.fzhucc.modules.subject.domain.dto.*;
import com.fzhucc.modules.subject.service.SubjectHighfieldsType1Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
* @website https://fzhucc.com
* @author yyg
* @since 2022-09-26 00:00:00
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "HUCC：省级管理")
@RequestMapping("/api/province")
public class SubjectHighfieldsType1Controller {

    private final SubjectHighfieldsType1Service subjectHighfieldsType1Service;

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@hu.check('province:list')")
    public void exportSubjectHighfieldsType1(HttpServletResponse response, SubjectHighfieldsType1QueryCriteria criteria) throws IOException {
        subjectHighfieldsType1Service.download(subjectHighfieldsType1Service.queryAll(criteria), response);
    }

    @GetMapping(value = "/queryProvince")
    @Log("查询省级")
    @ApiOperation("查询省级")
    @AnonymousAccess
    public PageDTO<SubjectHighfieldsType1QueryDto> querySubjectHighfieldsType1(SubjectHighfieldsType1QueryCriteria criteria, Pageable pageable){
        return subjectHighfieldsType1Service.queryAll(criteria,pageable);
    }

    @GetMapping(value = "/queryProvinceType")
    @Log("查询省市县")
    @ApiOperation("查询省市县")
    @AnonymousAccess
    public List<SubjectHighfieldsType1Result> querySubjectHighfieldsType(){
        List<SubjectHighfieldsType1Result> list = subjectHighfieldsType1Service.querySubjectHighfieldsType();
        return list;
    }

    @GetMapping(value = "/queryProvinceTypeH5")
    @Log("查询省市县h5")
    @ApiOperation("查询省市县h5")
    @AnonymousAccess
    public List<SubjectHighfieldsType1ResultH5> queryProvinceTypeH5(){
        List<SubjectHighfieldsType1ResultH5> list = subjectHighfieldsType1Service.querySubjectHighfieldsTypeH5();
        return list;
    }

    @GetMapping(value = "/queryAreah5")
    @Log("查询地区H5")
    @ApiOperation("查询地区H5")
    @AnonymousAccess
    public List<SubjectHighfieldsType1Result> queryAreah5(){
        List<SubjectHighfieldsType1Result> list = subjectHighfieldsType1Service.queryAreah5();
        return list;
    }

    @GetMapping(value = "/queryProvinceLabel")
    @Log("查询省市县label")
    @ApiOperation("查询省市县label")
    @AnonymousAccess
    public List<SubjectHighfieldsType1ResultLabel> querySubjectHighfieldsTypeLabel(){
        List<SubjectHighfieldsType1ResultLabel> list = subjectHighfieldsType1Service.queryProvinceLabel();
        return list;
    }

    @GetMapping(value = "/queryArea")
    @Log("查询地区")
    @ApiOperation("查询地区")
    @AnonymousAccess
    public List<SubjectHighfieldsType1ResultLabel> queryArea(){
        List<SubjectHighfieldsType1ResultLabel> list = subjectHighfieldsType1Service.queryArea();
        return list;
    }

    @PostMapping
    @Log("新增省级")
    @ApiOperation("新增省级")
    @PreAuthorize("@hu.check('province:add')")
    public SubjectHighfieldsType1QueryDto createSubjectHighfieldsType1(@Validated @RequestBody SubjectHighfieldsType1CreateDto resources){
        return subjectHighfieldsType1Service.create(resources);
    }

    @PutMapping
    @Log("修改省级")
    @ApiOperation("修改省级")
    @PreAuthorize("@hu.check('province:edit')")
    public void updateSubjectHighfieldsType1(@Validated @Update @RequestBody SubjectHighfieldsType1CreateDto resources){
        subjectHighfieldsType1Service.update(resources);
    }

    @DeleteMapping
    @Log("删除省级")
    @ApiOperation("删除省级")
    @PreAuthorize("@hu.check('province:del')")
    public void deleteSubjectHighfieldsType1(@RequestBody Integer[] ids) {
        subjectHighfieldsType1Service.deleteAll(ids);
    }
}